package com.dawn.module.cms.controller.app.company;

import com.dawn.framework.common.enums.CommonStatusEnum;
import com.dawn.framework.common.pojo.CommonResult;
import com.dawn.framework.common.pojo.PageParam;
import com.dawn.framework.common.pojo.PageResult;
import com.dawn.framework.common.util.object.BeanUtils;
import com.dawn.module.cms.controller.app.company.vo.AppCompanyPageReqVO;
import com.dawn.module.cms.controller.app.company.vo.AppCompanyRespVO;
import com.dawn.module.cms.dal.dataobject.company.CompanyDO;
import com.dawn.module.cms.service.company.CompanyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static com.dawn.framework.common.pojo.CommonResult.success;


@Tag(name = "用户 APP - 公司信息")
@RestController
@RequestMapping("/cms/company")
@Validated
public class AppCompanyController {

    @Resource
    private CompanyService companyService;

    @GetMapping("/get")
    @Operation(summary = "获得公司信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppCompanyRespVO> getCompany(@Valid AppCompanyPageReqVO pageReqVO) {
        pageReqVO.setPageNo(PageParam.PAGE_SIZE_NONE);
        pageReqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
        PageResult<CompanyDO> pageResult = companyService.getCompanyPage(pageReqVO);
        if (pageResult.getTotal() > 0){
            List<CompanyDO> companyDOList = pageResult.getList();
            return success(BeanUtils.toBean(companyDOList.get(0), AppCompanyRespVO.class));
        }else {
            return null;
        }
    }
}